package com.ytf.test.ninth.interfaces;

import java.io.IOException;
import java.nio.CharBuffer;
import java.util.Random;
import java.util.Scanner;

/**
 * @author: YTF
 * @date: 2025/1/26 11:29
 * @version: 1.0
 * @description:
 */
public class RandomWords implements Readable {
    /** 类和成员变量 */
    private static Random random = new Random(47);
    private static final char[] capitals = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
    private static final char[] lowers = "abcdefghijklmnopqrstuvwxyz".toCharArray();
    private static final char[] vowels = "aeiou".toCharArray();
    private int count;

    /** 构造函数 */
    public RandomWords(int count) {
        this.count = count;
    }

    /** 构造函数 */
    @Override
    public int read(CharBuffer cb) throws IOException {
        if (count-- == 0){
            return -1;
        }
        cb.append(capitals[random.nextInt(capitals.length)]);
        for (int i = 0; i <4 ; i++) {
            cb.append(vowels[random.nextInt(vowels.length)]);
            cb.append(lowers[random.nextInt(lowers.length)]);
        }
        cb.append(" ");
        return 10;
    }

    public static void main(String[] args) {
        Scanner scanner=new Scanner(new RandomWords(10));
        while (scanner.hasNext()){
            System.out.println(scanner.next());
        }
        /**
         * OutPut:
         * Yazeruyac
         * Fowenucor
         * Goeazimom
         * Raeuuacio
         * Nuoadesiw
         * Hageaikux
         * Ruqicibui
         * Numasetih
         * Kuuuuozog
         * Waqizeyoy
         *
         */
    }
}
